package com.test.neo4j.Mapper;
import com.test.neo4j.Entity.PersonRelationShip;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface PersonRelationShipRepository extends Neo4jRepository<PersonRelationShip, Long> {

    @Query("MATCH (startNode)-[r]->(relatedNode) " +
            " WHERE id(startNode) = $id  " +
            " RETURN startNode, r, relatedNode")
    List<PersonRelationShip> getRelateRelByStartNodeId(Long id);

    @Query("MATCH (startNode)-[r]->(relatedNode) " +
            " WHERE id(startNode) = $id OR id(relatedNode) = $id " +
            " RETURN startNode, r, relatedNode")
    List<PersonRelationShip> getRelateRelByNodeId(Long id);
    @Query("MATCH (startNode:Person)-[r]->(relatedNode:Person) " +
            " WHERE startNode.name = $name OR relatedNode.name = $name " +
            " RETURN startNode, r, relatedNode")
    List<PersonRelationShip> getRelateRelByNodeName(String name);

    @Query("MATCH (startNode)-[r]->(relatedNode)   RETURN count(r)")
    int getRelateRelCount(Long id);
}
